// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import 'amfe-flexible'
import './utils/flex'

Vue.config.productionTip = false
Vue.use(VueResource)

Vue.http.headers.post['Content-Type'] = 'application/json'
Vue.http.interceptors.push((request, next) => {
  // ...
  // 请求发送前的处理逻辑
  // console.log(request)
  request.beforeSend = function () {
    console.log(request.headers['Content-Type'])
  }
  next((response) => {
    if (!response.ok) {
      // alert(response.statusText)
    } else {
      if (response.data.status !== 0) {
        if (response.data.status === 10) {
          router.replace({
            path: 'login',
            query: {redirect: router.currentRoute.fullPath}
          })
        } else {
          // alert(response.data.msg)
        }
        // response.ok = false
      }
    }
    return response
  })
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
